home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 22 / Amiga Format AFCD22 (Jan 1998, Issue 106).iso / -seriously_amiga- / shareware / programming / other / gui4cli / g4c / fsearch / fsearch.gc next >
Text File  |  1997-11-17  |  14KB  |  588 lines

  1. G4C
  2.  
  3. ; $VER: FSearch.gc 1.1 
  4. ; by D.Keletsekis 15/9/97
  5.  
  6. ; GUI for the FSearch command
  7.  
  8. ; You must have FSearch 1.1 in the guis:c/fsearch directory, or
  9. ; else change the paths given in the 2 Launch commands.
  10.  
  11. ; This gui can be called as :
  12. ; GUILOAD guis:g4c/fsearch.gc SearchPath
  13.  
  14. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  15. ;
  16. ;                            Globals
  17. ;
  18. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  19.  
  20. WINBIG 103 22 409 159 'FSearch 1.1 by D.Keletsekis'
  21. WinType 11110001
  22. varpath 'fsearch.ft/dir.gc'
  23. winout  "kcon:0/100/690/170/FSearch Output/auto/close/wait"
  24. BOX 2 13 406 128 OUT button
  25.  
  26.  
  27. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  28. ;
  29. ;                           System events
  30. ;
  31. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  32.  
  33. xOnLoad
  34. setgad FSearch.gc 101  hide
  35. setgad FSearch.gc 201/250 hide
  36. setgad FSearch.gc 300/350 hide
  37. setgad FSearch.gc 325/333 off   ; size
  38. setgad FSearch.gc 305/306 off   ; date
  39. GuiOpen FSearch.gc
  40. ; the default values
  41. if $$ARG.0 > ''
  42.    searchpath = $$ARG.0
  43. else
  44.    searchpath = sys:
  45. endif
  46. file = '#?'
  47. subdirs = ALL
  48. findtxt = ''
  49. case = ''
  50. strsearch = On
  51. output = gui
  52. format = 'VERBOSE'
  53. nobin = ''
  54. nopath = ''
  55. details = ''
  56. highlight = HL
  57. min_size = ''
  58. max_size = ''
  59. from = ''
  60. to = ''
  61. header = ''
  62. update fsearch.gc 2 $searchpath
  63. setgad fsearch.gc 7 on
  64. ; load the file types
  65. lvuse fsearch.ft 1
  66. lvchange :fsearch.types
  67.  
  68. xOnClose
  69. GuiQuit FSearch.gc
  70. GuiQuit fsearch.ft      ; filetypes gui
  71.  
  72.  
  73. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  74. ;
  75. ;                          Gui Mode cycler
  76. ;
  77. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  78.  
  79. ; ---- a cycler to change the gui to its various modes
  80.  
  81. XCYCLER 2 0 186 13 "" guimode
  82. gadhelp 'Click to change the GUI mode'
  83. gadid 500
  84. gadkey m            ; use 'm' to cycle it
  85. CStr "FSearch Parameters"  PAR
  86. CStr "FSearch Settings" SET
  87. cstr "Date, Size & Type"  DATE
  88. cstr "FSearch Results" RES
  89. gosub FSearch.gc guichange
  90.  
  91. xroutine guichange
  92. docase $guimode
  93.   case = PAR
  94.        setgad FSearch.gc 1/13  show
  95.        setgad FSearch.gc 21/24 show
  96.        setgad FSearch.gc 101   hide
  97.        setgad FSearch.gc 300/350 hide
  98.        setgad FSearch.gc 201/250 hide
  99.        break
  100.   case = SET
  101.        setgad FSearch.gc 1/13  hide
  102.        setgad FSearch.gc 21/24 hide
  103.        setgad FSearch.gc 101   hide
  104.        setgad FSearch.gc 300/350 hide
  105.        setgad FSearch.gc 201/250 show
  106.        break
  107.   case = DATE
  108.        setgad FSearch.gc 1/13    hide
  109.        setgad FSearch.gc 21/24   hide
  110.        setgad FSearch.gc 101     hide
  111.        setgad FSearch.gc 201/250 hide
  112.        setgad FSearch.gc 300/350 show
  113.        break
  114.   case = RES
  115.        setgad FSearch.gc 1/13  hide
  116.        setgad FSearch.gc 21/24 hide
  117.        setgad FSearch.gc 101   show
  118.        setgad FSearch.gc 300/350 hide
  119.        setgad FSearch.gc 201/250 hide
  120.        break
  121. endcase
  122. ; redraw FSearch.gc
  123. ; NEW - using PARTREDRAW - looks great eh?
  124. partredraw FSearch.gc 4 15 402 124
  125.  
  126. if $guimode != RES
  127.     SetWintitle FSearch.gc 'FSearch by D. Keletsekis'
  128. endif
  129.  
  130.  
  131. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  132. ;
  133. ;                          Parameters
  134. ;
  135. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  136.  
  137. ; ------ choose searchpath(s)
  138.  
  139. BOX 10 20 388 64 in button
  140. gadid 12
  141.  
  142. CTEXT 20 25 "Search in :" #screen 8 2 0 0001
  143. gadid 1
  144.  
  145. XTEXTIN 18 37 350 13 "" searchpath sys: 100
  146. gadhelp 'This is the path FSearch will start searching from'
  147. gadid 2
  148. setgad FSearch.gc 5 on         ; set cursor to next textin gad
  149.  
  150. XBUTTON 370 37 18 13 "<"      ; choose a searchpath
  151. gadhelp 'Will pop-up a requester to let you choose a path'
  152. gadid 3
  153. ReqFile -1 -1 300 200 'Choose SearchPath:' DIR searchpath $searchpath
  154. update FSearch.gc 2 $searchpath
  155.  
  156. ; ---- filename pattern
  157.  
  158. CTEXT 21 54 "File name pattern :" #screen 8 2 0 0001
  159. gadid 4
  160.  
  161. XTEXTIN 17 65 371 13 "" file '#?' 100
  162. gadhelp 'Enter the filepattern wanted - #? means all files'
  163. gadid 5
  164. setgad FSearch.gc 7 on         ; set cursor to next textin gad
  165.  
  166. XCHECKBOX 364 24 25 9 "_Include sub-directories" subdirs ALL "" ON
  167. gadhelp 'Check ON to make FSearch recurse through all subdirectories'
  168. gadid 11
  169.  
  170. ; ---- text search
  171.  
  172. CTEXT 22 99 "Find text :" #screen 8 2 0 0001
  173. gadid 6
  174.  
  175. XTEXTIN 17 111 371 13 "" findtxt '' 100
  176. gadhelp 'Enter the text you want to find - or nothing for no text search.'
  177. gadid 7
  178.  
  179. BOX 9 92 389 37 IN BUTTON
  180. gadid 8
  181.  
  182. XCHECKBOX 360 97 25 9 "Case sensitive" case CS "" OFF
  183. gadhelp 'Check ON to make the search Case Sensitive'
  184. gadid 9
  185.  
  186.  
  187. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  188. ;
  189. ;                       Search results listview
  190. ;
  191. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  192.  
  193. XLISTVIEW 4 15 400 124 "" resfile "" 10 MULTI
  194. gadhelp "Here we'll display the results of the search"
  195. gadid 101
  196. gadfont #mono 8 001
  197.  
  198. ; deal with file - if running with dir.gc
  199. ifexists gui dir.gc
  200.    ; check the first characters
  201.  
  202.    ; use popup window to deal with choice, if it's a file
  203.  
  204.    if $resfile[0][4] = '›32m'
  205.        cutvar resfile[4] cut word  1 resfile
  206.        cutvar resfile cut char -4 temp   ; cut the csi
  207.        ifexists file $resfile
  208.            guiload guis:tools/rtn/FilePop $fsearch.gc/resfile
  209.        endif
  210.  
  211.    ; or it could be a file but with highlight off
  212.    
  213.    elseif $resfile[0][1] != ' '
  214.    and $resfile[0][1] != '›'
  215.        ifexists file $resfile
  216.            guiload guis:tools/rtn/FilePop $fsearch.gc/resfile
  217.        endif
  218.  
  219.    ; then it must be a line number.. I use CEd as an editor
  220.  
  221.    elseifexists port rexx_ced
  222.        cutvar resfile[4] cut word 1 resfile
  223.        sendrexx rexx_ced 'jump to line $resfile'
  224.    endif 
  225.  
  226. endif
  227.  
  228.  
  229.  
  230. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  231. ;
  232. ;                           FSearch settings
  233. ;
  234. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  235.  
  236. ; ------- output mode
  237.  
  238. BOX 23 28 175 71 in button
  239. gadid 201
  240.  
  241. XRADIO 156 38 18 9 output 2
  242. gadhelp 'Choose where you want the output from FSearch to go to'
  243. gadid 202
  244. rstr 'Output to Gui'   gui
  245. RStr 'Output to Shell' cli
  246.  
  247. ; ----------- Output format 
  248.  
  249. XRADIO 156 68 19 9 format 2
  250. gadhelp 'Says it all really..'
  251. gadid 203
  252. RStr  'Show text found' 'VERBOSE'
  253. RStr  'Filenames only'  ''
  254.  
  255. ; ------------ Settings - checkboxes
  256.  
  257. BOX 214 28 176 70 IN BUTTON
  258. gadid 208
  259.  
  260. XCHECKBOX 350 35 25 9 'Highlight results' highlight "HL" "" ON
  261. gadhelp 'Bask in the glory of colored ansi text - (OS V39)'
  262. gadid 205
  263.  
  264. XCHECKBOX 350 50 25 9 "Check binary files" nobin "" "NOBIN" ON
  265. gadhelp 'Check ON to make FSearch search binary files'
  266. gadid 211
  267.  
  268. XCHECKBOX 350 65 25 9 "Show File Path" nopath "" "NOPATH" ON
  269. gadhelp 'Will output filenames using their full path'
  270. gadid 212
  271.  
  272. XCHECKBOX 350 79 25 9 "Show File Details" details "INFO" "" OFF
  273. gadhelp 'Will also print out file size, date etc'
  274. gadid 213
  275.  
  276. ; ------- help & save settings
  277.  
  278. XBUTTON 299 119 91 13 "Help.."
  279. gadhelp 'Loads the FSearch.doc - the full Gui4Cli installation is needed'
  280. *FILENAME = '$$win.path\fsearch.readme'
  281. guiload guis:tools/read.gc
  282. guiopen read.gc
  283. gadid 220
  284.  
  285.  
  286.  
  287. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  288. ;
  289. ;                               DO IT!
  290. ;
  291. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  292.  
  293. ; This is where the commandline is formed and launched. The name of
  294. ; the variable which holds it is 'options'
  295.  
  296.  
  297. XBUTTON 20 143 91 13 "_Search"
  298. gadhelp 'Start the search!'
  299. gadid 501
  300. if $searchpath < ' '
  301.    setwintitle FSearch.gc 'Wrong parameters!'
  302.    stop
  303. endif
  304. SetWintitle FSearch.gc Searching...
  305.  
  306. ; --- construct the command line
  307.  
  308. options = '$searchpath '
  309. if $file != '#?'
  310. and $file > ' '
  311.     appvar options 'PAT=$file '
  312. endif
  313. if $findtxt > ' '
  314.     appvar options 'TXT=\"$findtxt\" $case '
  315. endif
  316. if $size = SIZE
  317.    if $min_size  > ' '
  318.    and $min_size > 0
  319.       min = $min_size
  320.       if $min_type = mb
  321.           min == $min * 1000
  322.       endif
  323.       appvar options 'MIN=$min '
  324.    endif
  325.    if $max_size  > ' '
  326.    and $max_size > 0
  327.       max = $max_size
  328.       if $max_type = mb
  329.           max == $max * 1000
  330.       endif
  331.       appvar options 'MAX=$max '
  332.    endif
  333.    if $min_size > $max_size
  334.    and $max_size != ''
  335.       ezreq 'Minimum size is more than\nMaximum size..' Ooops! ''
  336.       stop
  337.    endif
  338. endif
  339. if $date = DATED
  340.    if $from_date > ' '
  341.       appvar options 'FROM=$from_date '
  342.    endif
  343.    if $to_date > ' '
  344.       appvar options 'TO=$to_date '
  345.    endif
  346. endif
  347. extract header clean header
  348. if $header > ' '
  349. and $header != NONE
  350.    appvar options 'HEADER=$header'
  351.    appvar options '#? '
  352. endif
  353. appvar options '$format $nobin $nopath $details $highlight $subdirs'
  354.  
  355. ; disable gadgets
  356. setgad FSearch.gc 501/502 off
  357.  
  358. ; --- launch according to where it should output
  359.  
  360. if $output = cli
  361.       say '\n-------------- Search results :\n'
  362.       launch 1 'guis:c/FSearch $options'
  363.       say 'guis:c/FSearch $options\n'
  364. else
  365.       launch 2 'guis:c/FSearch >pipe:findres $options'
  366.       ; say 'guis:c/FSearch >pipe:findres $options\n'
  367.       update FSearch.gc 500 3        ; change gui to show results listview
  368.       guimode = RES
  369.       gosub FSearch.gc guichange
  370. endif
  371.  
  372. ; ---------- xONRETURN commands - handle returns according to launches
  373.  
  374. ; -- return from shell launch
  375.  
  376. xonreturn 1   ; to the shell
  377. say '-------------- Search finished.\n'
  378. setgad FSearch.gc 501/502 on
  379. SetWintitle FSearch.gc 'Search finished.'
  380.  
  381. ; -- return from gui output mode launch
  382.  
  383. xonreturn 2   ; to gui or file
  384. lvuse FSearch.gc 101
  385. setgad FSearch.gc 501/502 on
  386. SetWintitle FSearch.gc 'Search finished.'
  387.  
  388. ; -- the pipe event where the output is piped at
  389.  
  390. xpipe pipe:findres ON
  391. gadid 999
  392. lvuse FSearch.gc 101      ; whenever a line is available
  393. lvadd $$pipe              ; append it to our listv
  394.  
  395. ; -- We're all human..
  396.  
  397. xonfail
  398. setwintitle FSearch.gc '** Error **'
  399. setgad FSearch.gc 501/502 on
  400.  
  401.  
  402. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  403. ;
  404. ;                        Clear & cancel buttons
  405. ;
  406. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  407.  
  408. ; --------------- The CLEAR button - reset all settings
  409.  
  410. XBUTTON 205 143 91 13 "C_lear"
  411. gadhelp 'Clear the current gadgets - will not change hidden gadgets'
  412. gadid 502
  413. docase $guimode
  414.   case = PAR
  415.        file = #?
  416.        update FSearch.gc 5 $file
  417.        findtxt = ''
  418.        update FSearch.gc 7 ''
  419.        break
  420.   case = SET
  421.        break
  422.   case = DATE
  423.        date = ANY
  424.        update FSearch.gc 301 0
  425.        from_date = ''
  426.        update FSearch.gc 305 ''
  427.        to_date = ''
  428.        update FSearch.gc 306 ''
  429.        size = ANY
  430.        update FSearch.gc 321 0
  431.        min_size = ''
  432.        update FSearch.gc 325 ''
  433.        max_size = ''
  434.        update FSearch.gc 330 ''
  435.        min_type = kb
  436.        update FSearch.gc 329 0
  437.        max_type = kb
  438.        update FSearch.gc 333 0
  439.        setgad FSearch.gc 325/333 off   ; size
  440.        setgad FSearch.gc 305/306 off   ; date
  441.        header = NONE
  442.        update FSearch.gc 341 'All files'
  443.        break
  444.   case = RES
  445.        lvuse FSearch.gc 101   ; clear the lv
  446.        lvclear
  447.        break
  448. endcase
  449.  
  450. ; --------------- The CANCEL button
  451.  
  452. XBUTTON 300 143 91 13 "_Cancel"
  453. gadhelp 'Abort the Search!'
  454. gadid 503
  455. breaktask guis:c/FSearch C      ; break fsearch
  456. setgad FSearch.gc 999 CLEAN    ; stop & flush pipe output
  457. lvuse FSearch.gc 101
  458. lvadd "**** BREAK ****"
  459.  
  460.  
  461. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  462. ;
  463. ;                      SET DATE, SIZE & TYPE
  464. ;
  465. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  466.  
  467. ; The surrounding boxes
  468. BOX 13 17 381 47 in button
  469. gadid 335
  470. BOX 13 74 381 41 in button
  471. gadid 336
  472.  
  473. ; ----- Date
  474.  
  475. CTEXT 20 20 Date #screen 8 2 0 "0001"
  476. gadid 300
  477.  
  478. XRADIO 171 25 17 9 date 4
  479. gadid 301
  480. RStr 'Any date'    ANY
  481. RStr 'Files dated' DATED
  482. if $date = ANY
  483.    setgad FSearch.gc 305/306 off
  484. else
  485.    setgad FSearch.gc 305/306 on
  486. endif
  487.  
  488. XTEXTIN 298 31 77 12 "From:" from_date '' 100
  489. gadid 305
  490. setgad FSearch.gc 306 on
  491. XTEXTIN 298 45 77 12 "To:" to_date '' 100
  492. gadid 306
  493. setgad FSearch.gc 305 on
  494.  
  495. ; ----- Size
  496.  
  497. CTEXT 20 77 Size #screen 8 2 0 "0001"
  498. gadid 320
  499.  
  500. XRADIO 173 82 18 9 size 4
  501. gadid 321
  502. RStr 'Any size' ANY
  503. RStr 'Files sized' SIZE
  504. if $size = SIZE
  505.    setgad FSearch.gc 325/333 on
  506. else
  507.    setgad FSearch.gc 325/333 off
  508. endif
  509.  
  510. XTEXTIN 247 85 47 12 Over min_size "" 100
  511.   gadid 325
  512. XBUTTON 296 85 15 12 "<"
  513.   gadid 327
  514.   if $min_size > 0
  515.      counter min_size dec 1
  516.      update FSearch.gc 325 $min_size
  517.   endif
  518. XBUTTON 312 85 15 12 ">"
  519.   gadid 328
  520.   counter min_size inc 1
  521.   update FSearch.gc 325 $min_size
  522. XCYCLER 328 85 52 12 "" min_type
  523.   CStr Kb kb
  524.   CStr Mb mb
  525.   gadid 329
  526.  
  527. XTEXTIN 247 99 46 12 Under max_size "" 100
  528.   gadid 330
  529. XBUTTON 296 99 15 12 "<"
  530.   gadid 331
  531.   if $max_size > 0
  532.      counter max_size dec 1
  533.      update FSearch.gc 330 $max_size
  534.   endif
  535. XBUTTON 312 99 15 12 ">"
  536.   gadid 332
  537.   counter max_size inc 1
  538.   update FSearch.gc 330 $max_size
  539. XCYCLER 328 99 52 12 "" max_type
  540.   CStr Kb kb
  541.   CStr Mb mb
  542.   gadid 333
  543.  
  544. ; ----- File type
  545.  
  546. CTEXT 28 122 Type #screen 8 2 0 0001
  547. gadid 340
  548. TEXT 66 122 289 12 "All files" 80 BOX
  549. gadid 341
  550. XBUTTON 357 122 23 12 "<"
  551. gadid 342
  552. guiopen fsearch.ft
  553.  
  554. ; ##################################################################
  555. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  556. ;
  557. ;                            FSearch.ft
  558. ;
  559. ;         Gui with listview for choosing file header type
  560. ;
  561. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  562. ; ##################################################################
  563.  
  564. NEWFILE  fsearch.ft
  565.  
  566. WINBIG 245 109 179 116  ''
  567. WinType 00001000
  568. winonmouse 100 50
  569. varpath FSearch.gc
  570.  
  571. xoninactive
  572. guiclose fsearch.ft
  573.  
  574. xonrmb
  575. guiclose fsearch.ft
  576.  
  577. ; start off with empty listview - load the fsearch.types file in the
  578. ; fsearch.gc xonload event
  579.  
  580. XLISTVIEW 0 0 179 116  "" ftype '' 10 TXT
  581. gadid 1
  582. guiclose fsearch.ft
  583. cutvar ftype cut word -1 header
  584. update FSearch.gc 341 $ftype
  585.  
  586.  
  587.  
  588.